//
//  UIBarButtonItem+Extensions.swift
//  SwiftWeibo
//
//  Created by Stone on 16/12/2.
//  Copyright © 2016年 Stone. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    /// 创建一个UIBarButton
    ///
    /// - parameter title:    title
    /// - parameter fontSize: fontSize 默认16
    /// - parameter target:   target
    /// - parameter action:   action
    /// - parameter isBack:   是否加上返回箭头
    ///
    /// - returns: 返回一个barItem
    convenience init(title: String, fontSize: CGFloat = 16, target: Any?, action: Selector, isBack: Bool = false) {
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: 16, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        
        if isBack {
            
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage.init(named: imageName), for: .normal)
            btn.setImage(UIImage.init(named: imageName + "_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        self.init(customView: btn)
    }
    
}
